package com.chhuang.core.node;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @Description 带id 和 parentId 的树型结构
 * @Author Darren Huang
 * @Date 2024-03-15 9:05
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "BaseNode", description = "带id和parentId的树型结构的类")
public class BaseNode<PK extends Serializable> implements Serializable {

    private static final long serialVersionUID = 3526233231056646449L;

    /**
     * 主键ID
     */
    @ApiModelProperty(value = "主键ID")
    protected PK id;

    /**
     * 父节点ID
     */
    @ApiModelProperty(value = "父节点ID")
    protected PK parentId;

    /**
     * 层级
     */
    @ApiModelProperty(value = "层级")
    protected Integer type;

    /**
     * 子节点集合
     */
    @ApiModelProperty(value = "子节点集合")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    protected List<? extends BaseNode<PK>> children;

    /**
     * 设置节点值
     *
     * @param id       id
     * @param parentId 父id
     * @param type     层级
     */
     public void setNodeFields(PK id, PK parentId, Integer type) {
         this.id = id;
         this.parentId = parentId;
         this.type = type;
     }
}
